package impl;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import baise.BaseDaoImpl;
import baise.iHibBaseDAO;
import baise.iHibBaseDAOimpl;
import model.TBookRorrw;
import model.VBookBorrow;
import DAO.TBookRorrwDAO;
/**
 * 借阅实现类
 * @author Administrator
 *
 */
public class TBookRorrwDAOimpl implements TBookRorrwDAO {

	iHibBaseDAO iBaseDAO=new iHibBaseDAOimpl();
	@Override
	public boolean addBorrow(TBookRorrw tBorrow) {
		// TODO Auto-generated method stub
		return (Boolean) iBaseDAO.insert(tBorrow);
	}

	@Override
	public boolean deleteBorrow(TBookRorrw tBorrow) {
		// TODO Auto-generated method stub
		return iBaseDAO.delete(tBorrow);
	}

	@Override
	public boolean updateBorrow(TBookRorrw tBorrow) {
		// TODO Auto-generated method stub
		return iBaseDAO.update(tBorrow);
	}

	@Override
	public List<TBookRorrw> selectBorrow(int id) throws SQLException {
		// TODO Auto-generated method stub
		BaseDaoImpl bea=new BaseDaoImpl();
		String sql="SELECT * FROM V_BookBorrow  where userid= "+id;
		ResultSet rs=bea.select(sql);
		List<TBookRorrw> list=convertList(rs);
		return list;
	}
	private static List convertList(ResultSet rs) throws SQLException{
		List list = new ArrayList();
		ResultSetMetaData md = rs.getMetaData();//��ȡ����
		int columnCount = md.getColumnCount();//��ȡ�е�����
		while (rs.next()) {
			Map rowData = new HashMap();//����Map
				for (int i = 1; i <= columnCount; i++) {
					rowData.put(md.getColumnName(i), rs.getObject(i));//��ȡ����ֵ
				}
				list.add(rowData);
			}
		return list;
	}
	@Override
	public List<VBookBorrow> selectBorrowBook(int id) throws SQLException {
		BaseDaoImpl bea=new BaseDaoImpl();
		String sql="SELECT * FROM V_BookBorrow  where bookid= "+id;
		ResultSet rs=bea.select(sql);
		List<VBookBorrow> list=convertList(rs);
		return list;
	}

}
